<?php
    session_start();
    include("includes/connect.php");
    include("functions/registration_functions.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="application/json">
<title>Star Map Mobile</title>
</head>
</html>
<?php
 	$username = $_GET['username'];
	$ChkPt1 = ChkUserName($username);

	if($ChkPt1 == 1)
	{
		$email = $_GET['email'];
		$ChkPt2 = ChkEmail($email);
		
		echo json_encode("EMAIL: SUCCESS<br>");
		$error = 0;

		if($ChkPt2 == 1)
		{
			$passworda = $_GET['passworda'];
			$passwordb = $_GET['passwordb'];
			$ChkPt3 = ChkPassword($passworda,$passwordb);
			
			echo json_encode("PASSWORD: SUCCESS<br>");
			$error = 0;

            if($ChkPt3 == 1)
            {
                $MD5Password = md5($passworda);
				
				echo json_encode("USERNAME: SUCCESS<br>");
				$error = 0;

                if($ChkPt1 == 1 && $ChkPt2 == 1 && $ChkPt3 == 1)
                {
                    $InsertNewUser = "INSERT INTO `user_table` (`username`, `password`, `email`, `GID`) VALUES ('$username', '$MD5Password', '$email', '2')";
                    mysql_query($InsertNewUser) or die("could not register users or send email out");
					
					echo json_encode("REGISTRATION: SUCCESS");
                    $error = 0;
                }
                else
				{ 
					$error = 1;
					echo json_encode("REGISTRATION: FAILURE"); 
				}
            }
            else
			{ 
				$error = 1;
				echo json_encode("USERNAME: FAILURE");
			}
        }
        else
		{
			$error = 1;
			echo json_encode("PASSWORD: FAILURE");
		}
    }
    else
	{
		$error = 1;
		echo json_encode("EMAIL: FAILURE");
	}

?>